package com.zengde.ai_sandbox.service.impl;

import com.zengde.ai_sandbox.dto.ChatMessage;
import com.zengde.ai_sandbox.service.ChatService;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class ChatServiceImpl implements ChatService {

    private final RestTemplate restTemplate;
    private final String API_URL = "http://localhost:8080/nt-ns-byLang-withDb";

    public ChatServiceImpl() {
        this.restTemplate = new RestTemplate();
    }

    @Override
    public String getResponse(ChatMessage chatMessage) {
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);

        HttpEntity<ChatMessage> request = new HttpEntity<>(chatMessage, headers);
        
        return restTemplate.postForObject(API_URL, request, String.class);
    }
} 